package be.webchess.www.logic.impl;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import be.webchess.www.dao.UserDAO;
import be.webchess.www.model.ActionHistory;
import be.webchess.www.model.ChessBoard;
import be.webchess.www.model.ChessPiece;
import be.webchess.www.model.User;

public class ChessGameLogic {

	ChessBoard			cb;
	
	public ChessGameLogic( ChessBoard cb )
	{
		this.cb = cb;
	}
	
	//
		
	private Map<String, Integer>		getPieceMovements ( String mov )
	{
		Map<String, Integer>	result = new TreeMap<String, Integer>();
		String[]	neg_pos;
		String[]	vals;
		       			
		neg_pos = mov.split(":");
				
		if ( neg_pos.length > 1 )
		{
			vals = neg_pos[0].split(",");
			
			if ( vals.length > 3 )
			{
				result.put( "+x", Integer.parseInt(vals[0]) );
				result.put( "+y", Integer.parseInt(vals[1]) );
				result.put( "+zl", Integer.parseInt(vals[2]) );
				result.put( "+zr", Integer.parseInt(vals[3]) );
			}
			
			vals = neg_pos[1].split(",");
			
			if ( vals.length > 3 )
			{
				result.put( "-x", Integer.parseInt(vals[0]) );
				result.put( "-y", Integer.parseInt(vals[1]) );
				result.put( "-zl", Integer.parseInt(vals[2]) );
				result.put( "-zr", Integer.parseInt(vals[3]) );
			}
		}
		
		return result;
	}
	
	private String			makeStringFromPosition ( char l, char n )
	{
		StringBuffer		b = new StringBuffer();
		
		b.append(l);
		b.append(n);
		
		return b.toString();
	}
	
	private List<String>			getCorrectMoves ( ChessBoard cb, String from, Map<String, Integer> imovs )
	{
		List<String>	lst = new ArrayList<String>();
		
		ChessPiece		p = cb.getMatrix().get(from);
		ChessPiece		tp;
		char			letter = from.charAt(0);
		char			num = from.charAt(1);
		char			pnum;
		boolean			pcond;
		
		//
		
		
		switch(p.getType())
		{
			case EPT_KING:

				String	tmp_pos;
				char	knum = (char)(num);		
				char	kletter = (char)(letter);
				
				if ( knum >= '1' && knum <= '8' )
				{
					if ( (char)(kletter - 1) >= 'a' && (char)(kletter - 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter-1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}
					if ( (char)(kletter + 1) >= 'a' && (char)(kletter + 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter+1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}					
				}
				
				knum = (char)(num + 1);	
				
				if ( knum >= '1' && knum <= '8' )
				{
					if ( (char)(kletter) >= 'a' && (char)(kletter) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}					
					if ( (char)(kletter - 1) >= 'a' && (char)(kletter - 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter-1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}
					if ( (char)(kletter + 1) >= 'a' && (char)(kletter + 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter+1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}					
				}
				
				knum = (char)(num - 1);
				
				if ( knum >= '1' && knum <= '8' )
				{
					if ( (char)(kletter) >= 'a' && (char)(kletter) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}					
					if ( (char)(kletter - 1) >= 'a' && (char)(kletter - 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter-1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}
					if ( (char)(kletter + 1) >= 'a' && (char)(kletter + 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter+1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}					
				}
				
				return lst;
		
			case EPT_KNIGHT:
				
				knum = (char)(num + 2);		
				kletter = (char)(letter);
								
				if ( knum >= '1' && knum <='8' )
				{
					if ( (char)(kletter - 1) >= 'a' && (char)(kletter - 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter-1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);
					}
					if ( (char)(kletter + 1) >= 'a' && (char)(kletter + 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter+1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
				}
				
				knum = (char)(num - 2);
				
				if ( knum >= '1' && knum <='8' )
				{
					if ( (char)(kletter - 1) >= 'a' && (char)(kletter - 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter-1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
					if ( (char)(kletter + 1) >= 'a' && (char)(kletter + 1) <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(kletter+1),knum);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
				}				
				
				knum = num;
				kletter = (char)(letter + 2);
				
				if ( kletter >= 'a' && kletter <='h' )
				{
					if ( (char)(knum - 1) >= '1' && (char)(knum - 1) <= '8' )
					{
						tmp_pos = makeStringFromPosition(kletter,(char)(knum-1));
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
					if ( (char)(knum + 1) >= '1' && (char)(knum + 1) <= '8' )
					{						
						tmp_pos = makeStringFromPosition(kletter,(char)(knum+1));
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
				}				
				
				kletter = (char)(letter - 2);
				
				if ( kletter >= 'a' && kletter <='h' )
				{
					if ( (char)(knum - 1) >= '1' && (char)(knum - 1) <= '8' )
					{
						tmp_pos = makeStringFromPosition(kletter,(char)(knum-1));
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
					if ( (char)(knum + 1) >= '1' && (char)(knum + 1) <= '8' )
					{
						tmp_pos = makeStringFromPosition(kletter,(char)(knum+1));
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
						else if ( tp == null )
							lst.add(tmp_pos);						
					}
				}				
				
				return lst;
				
			case EPT_PAWN:
				
				if ( p.getColor().compareToIgnoreCase("white") == 0 )
				{
					pnum = (char)(num + imovs.get("+y"));
					num += 1;
					pcond = num<=pnum;
				}
				else
				{
					pnum = (char)(num - imovs.get("+y"));
					num -= 1;
					pcond = num>=pnum;
				}								
				
				for(char n = num;pcond;)
				{
					if ( n <= '8' && n >= '1' )
					{			
						tmp_pos = makeStringFromPosition(letter,n);
						
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp == null )
							lst.add(tmp_pos);
						else
							break;
					}
					
					if ( p.getColor().compareToIgnoreCase("white") == 0 )
					{
						n++;
						pcond = n<=pnum;
					}
					else
					{
						n--;
						pcond = n>=pnum;
					}
				}
				
				if ( num <= '8' && num >= '1' )
				{										
					if ( letter+1 <= 'h' )
					{
						tmp_pos = makeStringFromPosition((char)(letter+1),num);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
					}
					
					if ( letter-1 >= 'a' )
					{
						tmp_pos = makeStringFromPosition((char)(letter-1),num);
						tp = cb.getMatrix().get(tmp_pos);
						
						if ( tp != null && tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
							lst.add(tmp_pos);
					}				
				}
				
				return lst;
		}
		
		//
		if ( imovs.get("+x") == -1 )
		{
			for(char l = (char)(letter+1);l<='h';l++)
			{
				String tmp_pos = makeStringFromPosition(l,num);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}
		}
		
		if ( imovs.get("-x") == -1 )
		{
			for(char l = (char)(letter-1);l>='a';l--)
			{
				String tmp_pos = makeStringFromPosition(l,num);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}					
		}
		//
		
		if ( imovs.get("+y") == -1 )
		{
			for(char n = (char)(num+1);n<='8';n++)
			{
				String tmp_pos = makeStringFromPosition(letter,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}
		}
		
		if ( imovs.get("-y") == -1 )
		{
			for(char n = (char)(num-1);n>='1';n--)
			{
				String tmp_pos = makeStringFromPosition(letter,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}			
		}
		
		//
		
		if ( imovs.get("+zl") == -1 )
		{
			for(char n = (char)(num+1),l = (char)(letter-1);n<='8'&&l>='a';n++,l--)
			{
				String tmp_pos = makeStringFromPosition(l,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}
		}
		
		if ( imovs.get("-zl") == -1 )
		{
			for(char n = (char)(num-1),l = (char)(letter+1);n>='1'&&l<='h';n--,l++)
			{
				String tmp_pos = makeStringFromPosition(l,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}				
		}				
		
		if ( imovs.get("+zr") == -1 )
		{
			for(char n = (char)(num+1),l = (char)(letter+1);n<='8'&&l<='h';n++,l++)
			{
				String tmp_pos = makeStringFromPosition(l,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}
		}
		
		if ( imovs.get("-zr") == -1 )
		{
			for(char n = (char)(num-1),l = (char)(letter-1);n>='1'&&l>='a';n--,l--)
			{
				String tmp_pos = makeStringFromPosition(l,n);
				tp = cb.getMatrix().get(tmp_pos);
				
				if ( tp != null )
				{
					if ( tp.getColor().compareToIgnoreCase(p.getColor()) != 0 )
						lst.add ( tmp_pos );
						
					break;
				}
				else
					lst.add( tmp_pos );
			}				
		}					
		
		///////////////////////////////////////////
		
		
		
		return lst;
	}
	
	//
	
	public List<String>		getCorrectMovePositions ( String from )
	{
		List<String>	lst = null;
		Map<String, Integer>	movs;
		Map<String, Integer>	imovs;
		
		try
		{
			ChessPiece		p = cb.getMatrix().get(from);
			
			movs = getPieceMovements(p.getMovements());
			imovs = getPieceMovements(p.getInit_movements());

			if ( isPieceAtInitialPosition (from) )
			{
				lst = getCorrectMoves(cb, from, imovs);				
			}else
			{
				lst = getCorrectMoves(cb, from, movs);
			}
						
		} catch ( Exception ex )
		{			
		}		
		
		return lst;
	}
	
	public boolean 		checkMovePiece ( String from, String to )
	{
		ChessPiece		p = cb.getMatrix().get(from);
		List<String>	lst;
		
		if ( p == null || from.compareToIgnoreCase("00") == 0 )
			return false;
		
		lst = getCorrectMovePositions(from);
		
		for ( String i : lst )
		{
			if ( i.compareToIgnoreCase(to) == 0 ) // Can move to that position
				return true;
		}
		
		return false;
	}
		
	public boolean		movePiece ( String from, String to )
	{
		ChessPiece		p = cb.getMatrix().get(from);
		ChessPiece		t = cb.getMatrix().get(to);
		
		if ( p == null || from.compareToIgnoreCase("00") == 0 )
			return false;
		
		if ( getCurrentPlayerColor().compareToIgnoreCase(p.getColor()) != 0 )
			return false;
		
		if ( !checkMovePiece(from, to) )
			return false;
				
		if ( t != null )
		{
			cb.getMatrix().remove(to);
			t.setLocation("00");
		}
		
		cb.getMatrix().put("00", t);
						
		cb.getMatrix().remove(from);
		cb.getMatrix().put(to, p);
		p.setLocation(to);
		p.setFlags( p.getFlags() & (~ChessPiece.EPF_INITIAL_POSITION) );
				
		return true;
	}
	
	public boolean 		isPieceAtInitialPosition ( String from )
	{
		try
		{
			ChessPiece		p = cb.getMatrix().get(from);
		
			if ( (p.getFlags() & ChessPiece.EPF_INITIAL_POSITION) > 0 )
			{
				return true;
			}
			
		} catch ( Exception ex )
		{			
		}
		
		return false;
	}
	
	public User			getCurrentPlayer ()
	{
		if ( cb.getNextPlayerColor().compareToIgnoreCase("white") == 0 )
			return cb.getBlackPlayer();

		return cb.getWhitePlayer();
	}
	
	public String		getCurrentPlayerColor ()
	{
		if ( cb.getNextPlayerColor().compareToIgnoreCase("white") == 0 )
			return "black";
		
		return "white";
	}
	
	public void			setCurrentPlayerColor ( String color )
	{
		if ( color.compareToIgnoreCase("white") == 0 )
			cb.setNextPlayerColor("black");
		else
			cb.setNextPlayerColor("white");
	}
	
	public String		toggleCurrentPlayer ()
	{
		String		color = getCurrentPlayerColor();
		if ( color.compareToIgnoreCase("white") == 0 )
			setCurrentPlayerColor("black");
		else
			setCurrentPlayerColor("white");
		
		return color;
	}

	public void			createIntialMatrix ()
	{
		Map<String, ChessPiece> 	matrix = new TreeMap<String, ChessPiece>();
		List<ChessPiece>		pieces = new LinkedList<ChessPiece>();
		
		//
				
		matrix.put("a1", ChessPiece.createInitialPiece("a1", ChessPiece.PieceType.EPT_ROOK, cb, "white") );
		matrix.put("b1", ChessPiece.createInitialPiece("b1", ChessPiece.PieceType.EPT_KNIGHT, cb, "white") );
		matrix.put("c1", ChessPiece.createInitialPiece("c1", ChessPiece.PieceType.EPT_BISHOP, cb, "white") );
		matrix.put("d1", ChessPiece.createInitialPiece("d1", ChessPiece.PieceType.EPT_QUEEN, cb, "white") );
		matrix.put("e1", ChessPiece.createInitialPiece("e1", ChessPiece.PieceType.EPT_KING, cb, "white") );
		matrix.put("f1", ChessPiece.createInitialPiece("f1", ChessPiece.PieceType.EPT_BISHOP, cb, "white") );
		matrix.put("g1", ChessPiece.createInitialPiece("g1", ChessPiece.PieceType.EPT_KNIGHT, cb, "white") );
		matrix.put("h1", ChessPiece.createInitialPiece("h1", ChessPiece.PieceType.EPT_ROOK, cb, "white") );
			
		matrix.put("a2", ChessPiece.createInitialPiece("a2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("b2", ChessPiece.createInitialPiece("b2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("c2", ChessPiece.createInitialPiece("c2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("d2", ChessPiece.createInitialPiece("d2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("e2", ChessPiece.createInitialPiece("e2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("f2", ChessPiece.createInitialPiece("f2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("g2", ChessPiece.createInitialPiece("g2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		matrix.put("h2", ChessPiece.createInitialPiece("h2", ChessPiece.PieceType.EPT_PAWN, cb, "white") );
		
		matrix.put("a8", ChessPiece.createInitialPiece("a8", ChessPiece.PieceType.EPT_ROOK, cb, "black") );
		matrix.put("b8", ChessPiece.createInitialPiece("b8", ChessPiece.PieceType.EPT_KNIGHT, cb, "black") );
		matrix.put("c8", ChessPiece.createInitialPiece("c8", ChessPiece.PieceType.EPT_BISHOP, cb, "black") );
		matrix.put("d8", ChessPiece.createInitialPiece("d8", ChessPiece.PieceType.EPT_QUEEN, cb, "black") );
		matrix.put("e8", ChessPiece.createInitialPiece("e8", ChessPiece.PieceType.EPT_KING, cb, "black") );
		matrix.put("f8", ChessPiece.createInitialPiece("f8", ChessPiece.PieceType.EPT_BISHOP, cb, "black") );
		matrix.put("g8", ChessPiece.createInitialPiece("g8", ChessPiece.PieceType.EPT_KNIGHT, cb, "black") );
		matrix.put("h8", ChessPiece.createInitialPiece("h8", ChessPiece.PieceType.EPT_ROOK, cb, "black") );		
		
		matrix.put("a7", ChessPiece.createInitialPiece("a7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("b7", ChessPiece.createInitialPiece("b7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("c7", ChessPiece.createInitialPiece("c7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("d7", ChessPiece.createInitialPiece("d7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("e7", ChessPiece.createInitialPiece("e7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("f7", ChessPiece.createInitialPiece("f7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("g7", ChessPiece.createInitialPiece("g7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );
		matrix.put("h7", ChessPiece.createInitialPiece("h7", ChessPiece.PieceType.EPT_PAWN, cb, "black") );	
		//
		
		pieces.add(matrix.get("a1"));
		pieces.add(matrix.get("b1"));
		pieces.add(matrix.get("c1"));
		pieces.add(matrix.get("d1"));
		pieces.add(matrix.get("e1"));
		pieces.add(matrix.get("f1"));
		pieces.add(matrix.get("g1"));
		pieces.add(matrix.get("h1"));
		
		pieces.add(matrix.get("a2"));
		pieces.add(matrix.get("b2"));
		pieces.add(matrix.get("c2"));
		pieces.add(matrix.get("d2"));
		pieces.add(matrix.get("e2"));
		pieces.add(matrix.get("f2"));
		pieces.add(matrix.get("g2"));
		pieces.add(matrix.get("h2"));

		pieces.add(matrix.get("a8"));
		pieces.add(matrix.get("b8"));
		pieces.add(matrix.get("c8"));
		pieces.add(matrix.get("d8"));
		pieces.add(matrix.get("e8"));
		pieces.add(matrix.get("f8"));
		pieces.add(matrix.get("g8"));
		pieces.add(matrix.get("h8"));

		pieces.add(matrix.get("a7"));
		pieces.add(matrix.get("b7"));
		pieces.add(matrix.get("c7"));
		pieces.add(matrix.get("d7"));
		pieces.add(matrix.get("e7"));
		pieces.add(matrix.get("f7"));
		pieces.add(matrix.get("g7"));
		pieces.add(matrix.get("h7"));
		
		//
		
		cb.setMatrix(matrix);
		cb.setPieces(pieces);
	}
	
	public Map<String, ChessPiece> getChessBoardMatrix ()
	{
		return cb.getMatrix();
	}
}
